/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.inria.openmath.omapi.implementation;

/**
 *
 * @author Mr.Sam
 */

import java.io.*;
import java.math.BigInteger;
import fr.inria.openmath.omapi.*;

public class PipeParserHandler extends ParserAdapter {

    Printer printer;

    public PipeParserHandler (Printer printer) {
        this.printer = printer;
    }

    public PipeParserHandler () {
        this(new XMLPrinter(new DataOutputStream(System.out)));
    }

    /**
     * Set the printer.
     */
    public void setPrinter(Printer printer) {
        this.printer = printer;
    }

    /**
     * Get the printer.
     */
    public Printer getPrinter() {
        return this.printer;
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endParse
     */
    public void endParse() throws OMException {
        try {
            printer.endPrint();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#startObject
     */
    public void startObject() throws OMException {
        try {
            printer.putBeginObject();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }

    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endObject
     */
    public void endObject() throws OMException {
        try {
            printer.putEndObject();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }



    /**
     * @see fr.inria.openmath.omapi.ParserHandler#startApplication
     */
    public void startApplication() throws OMException {
        try {
            printer.putBeginApplication();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endApplication
     */
    public void endApplication() throws OMException {
        try {
            printer.putEndApplication();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }



    /**
     * @see fr.inria.openmath.omapi.ParserHandler#startAttribution
     */
    public void startAttribution() throws OMException {
        try {
            printer.putBeginAttribution();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endAttribution
     */
    public void endAttribution() throws OMException {
        try {
            printer.putEndAttribution();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#startAttributePairs
     */
    public void startAttributePairs() throws OMException {
        try {
            printer.putBeginAttributePairs();
        } catch (Exception e) {
            throw new OMException(e);
        }

    }



    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endAttributePairs
     */
    public void endAttributePairs() throws OMException {
        try {
            printer.putEndAttributePairs();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#startBind
     */
    public void startBind() throws OMException {
        try {
            printer.putBeginBind();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endBind
     */
    public void endBind() throws OMException {
        try {
            printer.putEndBind();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#startBVars
     */
    public void startBVars() throws OMException {
        try {
            printer.putBeginBVars();
        } catch (Exception e) {
            throw new OMException(e);
        }

    }



    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endBVars
     */
    public void endBVars() throws OMException {
        try {
            printer.putEndBVars();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#startError
     */
    public void startError() throws OMException {
        try {
            printer.putBeginError();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#endError
     */
    public void endError() throws OMException {
        try {
            printer.putEndError();
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readInteger
     */
    public void readInteger(int value) throws OMException {
        try {
            printer.putInteger(value);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OMException(e);
        }
    }

    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readInteger
     */
    public void readInteger(BigInteger value) throws OMException {
        try {
            printer.putInteger(value);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OMException(e);
        }
    }

    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readFloat
     */
    public void readFloat(double value) throws OMException {
        try {
            printer.putFloat(value, 16);
        } catch (Exception e) {
            throw new OMException(e);
        }
    }

    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readString
     */
    public void readString(String value) throws OMException {
        try {
            printer.putString(value);
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readVariable
     */
    public void readVariable(String name) throws OMException {
        try {
            printer.putVariable(name);
        } catch (Exception e) {
            throw new OMException(e);
        }

    }



    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readByteArray
     */
    public void readByteArray(byte[] value) throws OMException {
        try {
            printer.putByteArray(value);
        } catch (Exception e) {
            throw new OMException(e);
        }
    }


    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readSymbol
     */
    public void readSymbol(Symbol value) throws OMException {
        try {
            printer.putSymbol(value);
        } catch (Exception e) {
            throw new OMException(e);
        }

    }

    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readComment
     */
    public void readComment(String comment) throws OMException {
        try {
            printer.putComment(comment);
        } catch (Exception e) {
            throw new OMException(e);
        }
    }

    /**
     * @see fr.inria.openmath.omapi.ParserHandler#readPInstruction
     */
    public void readPInstruction(String pi) throws OMException {
        try {
            printer.putPInstruction(pi);
        } catch (Exception e) {
            throw new OMException(e);
        }
    }

}
